/**
 * 工具库
 */
var isMobile = (function (a, b) {
	if (a && b !== undefined && b) {
		a = a.toLowerCase();
	}
	var deviceKeys = ["iPhone", "iPad", "iPod", "Android", "Mobile", "Linux", "SymbianOS", "BlackBerry", "Phone"],
		index;
	for (var i = 0; i < deviceKeys.length; i++) {
		index = a.indexOf(deviceKeys[i].toLowerCase());
		if (index != -1) {
			return true;
		}
	}
	return false;
})(navigator.userAgent, LIM.config["isOpenPhoneAccess"]);
if (!UT) var UT = {};
UT.getElementLeft = function (obj) {
	var x = obj.offsetLeft;
	while (obj = obj.offsetParent)
	x += obj.offsetLeft;
	return x + 'px';
};
UT.addHoverEffect = function (element) {
	this.addEvent(element, "mouseover", function (e) {
		var e = e || window.event,
			object = e.srcElement || e.target;
		object.className += " hover";
	});
	this.addEvent(element, "mouseout", function (e) {
		var e = e || window.event,
			object = e.srcElement || e.target;
		object.className = object.className.replace(" hover", '');
	});
};
UT.getCookie = function (name) {
	var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
	arr = document.cookie.match(reg);
	if (arr) {
		return unescape(arr[2]);
	} else {
		return null;
	}
};
UT.URLToParams = function (params) {
	try {
		var cmdMap = params.split("&"),
			cmdParams = [],
			temp;
		for (var i = 0; i < cmdMap.length; i++) {
			temp = cmdMap[i].split("=");
			cmdParams[temp[0]] = temp[1];
		}
		return cmdParams;
	} catch (e) {
		E.report(LIM.localRes["paramModifyError"], '1206');
		return [];
	}
};
UT.getURL = function (url) {
	if (typeof decodeURIComponent != "undefined") {
		return decodeURIComponent(url);
	} else {
		return decodeURI(url);
	}
};
UT.ParamsToUrl = function (params) {
	var url = "";
	for (var name in params) {
		if (name && params[name] && typeof params[name] != "function") {
			url += name + "=" + params[name] + "&";
		}
	}
	if (url != "") {
		url = url.substring(0, url.length - 1);
	}
	return url;
};
UT.URLDecode = function (Str) {
	if (Str == null || Str == "") {
		return "";
	}
	var newStr = "";

	function toCase(sStr) {
		return sStr.toString(16).toUpperCase();
	};
	for (var i = 0, ichar, len = Str.length; i < len;) {
		if (Str.charAt(i) == "%") {
			ichar = Str.charAt(i + 1);
			if (ichar.toLowerCase() == "e") {
				newStr += String.fromCharCode(((parseInt("0x" + Str.substr(i + 1, 2)) - 0xE0) * 0x1000) + ((parseInt("0x" + Str.substr(i + 4, 2)) - 0x80) * 0x40) + (parseInt("0x" + Str.substr(i + 7, 2)) - 0x80));
				i += 9;
			} else if (ichar.toLowerCase() == "c" || ichar.toLowerCase() == "d") {
				newStr += String.fromCharCode(((parseInt("0x" + Str.substr(i + 1, 2)) - 0xC0) * 0x40) + parseInt("0x" + Str.substr(i + 4, 2)) - 0x80);
				i += 6;
			} else {
				newStr += String.fromCharCode(parseInt("0x" + Str.substr(i + 1, 2)));
				i += 3;
			}
		} else {
			newStr += Str.charAt(i).replace(/\+/, " ");
			i++;
		}
	}
	return newStr;
};
UT.XMLEncode = function (str) {
	var i, c, ir, ret = "",
		strSpecial = "&<>",
		strReplace = "amp;&lt;&gt;".split("&");
	for (i = 0; i < str.length; i++) {
		c = str.charAt(i);
		if (c == " ") ret += "&nbsp;";
		else if ((ir = strSpecial.indexOf(c)) != -1) ret += "&" + strReplace[ir];
		else ret += c;
	}
	var newlineRegExp = new RegExp("(\r\n|\n)", "g");
	if (ret != null) ret = ret.replace(newlineRegExp, "<br/>");
	return ret;
};
UT.URLEncode = function (Str) {
	if (Str == null || Str == "") {
		return "";
	}
	var newStr = "";
	var toCase = function (sStr) {
		return sStr.toString(16).toUpperCase();
	};
	for (var i = 0, icode, len = Str.length; i < len; i++) {
		icode = Str.charCodeAt(i);
		if (icode < 0x10) {
			newStr += "%0" + icode.toString(16).toUpperCase();
		} else if (icode < 0x80) {
			if (icode == 0x20) {
				newStr += "+";
			} else if ((icode >= 0x30 && icode <= 0x39) || (icode >= 0x41 && icode <= 0x5A) || (icode >= 0x61 && icode <= 0x7A)) {
				newStr += Str.charAt(i);
			} else {
				newStr += "%" + toCase(icode);
			}
		} else if (icode < 0x800) {
			newStr += "%" + toCase(0xC0 + (icode >> 6));
			newStr += "%" + toCase(0x80 + icode % 0x40);
		} else {
			newStr += "%" + toCase(0xE0 + (icode >> 12));
			newStr += "%" + toCase(0x80 + (icode >> 6) % 0x40);
			newStr += "%" + toCase(0x80 + icode % 0x40);
		}
	}
	return newStr;
};
UT.loadImg = function (that) {
	var objImg = that;
	var url = objImg.getAttribute('imgUrl');
	if (typeof url == 'undefined' || url == '') {
		return
	}
	this.imgReady = function (url, callback, error) {
		var img = new Image(),
			body = document.body;
		if (img.complete) {
			return callback(img.width, img.height);
		}
		img.onload = function () {
			img.onload = img.onerror = null;
			callback(img.width, img.height);
		};
		img.onerror = function () {
			error && error();
		};
		img.src = url;
	};
	this.imgReady(url,
	function (width, height) {
		var win_width = $("#history").width();
		var win_height = $("#history").height();
		var height2;
		objImg.removeAttribute("imgUrl");
		objImg.removeAttribute("onload");
		objImg.onload = null;
		objImg.removeAttribute("src");
		objImg.setAttribute("src", url);
		objImg.setAttribute('width', 100);
		objImg.setAttribute('height', 100);
		globalChatHandle.scrollHistoryToBottom();
	}, function () {
		objImg.src = 'refactor/style/images/loaderro.png';
		objImg.removeAttribute("imgUrl");
		objImg.removeAttribute("onload");
		objImg.style.width = '63px';
		objImg.style.height = '48px';
		globalChatHandle.scrollHistoryToBottom();
	});
};
UT.setImageScale = function (obj, maxWidth, maxHeight) {
	var widthtmp = obj.width;
	var heighttmp = obj.height;
	if (widthtmp > maxWidth) {
		heighttmp *= maxWidth / widthtmp;
		widthtmp = maxWidth;
	}
	if (heighttmp > maxWidth) {
		widthtmp *= maxWidth / heighttmp;
		heighttmp = maxWidth;
	}
	obj.width = widthtmp;
	obj.height = heighttmp;
};
UT.isEnglish = function (name) {
	if (name.length == 0) return false;
	for (i = 0; i < name.length; i++) {
		if (name.charCodeAt(i) > 128) return false;
	}
	return true;
};
UT.isMail = function (name) {
	if (!this.isEnglish(name)) return false;
	i = name.indexOf("@");
	j = name.lastIndexOf("@");
	if (i == -1) return false;
	if (i != j) return false;
	if (i == name.length) return false;
	return true;
};
//将字符串转换成json对象
UT.strToJson = function (str) {
	var json = null;
	if (str) {
		json = eval('(' + str + ')');
	}
	return json;
};
/*
 * xxx,new-xxx,old-custom-xxx,new-custom-xxx
 * mobile-xxx,mobile-custom-xxx
 * inner-xxx,inner-custom-xxx*/
UT.skinURI = function (skinName) {
	if ((new RegExp("old-custom-")).test(skinName) || (new RegExp("new-custom-")).test(skinName)) {
		return "custom/alert/" + skinName;
	} else if ((new RegExp("mobile-")).test(skinName)) {
		if ((new RegExp("mobile-custom-")).test(skinName)) {
			return "custom/mobile/" + skinName;
		}
		return "default/mobile/" + skinName;
	} else if ((new RegExp("inner-")).test(skinName)) {
		if ((new RegExp("inner-custom-")).test(skinName)) {
			return "custom/inner/" + skinName;
		}
		return "default/inner/" + skinName;
	} else {
		return "default/alert/" + skinName;
	}
};
UT.showImg = function(that) {
	var cutImage = new Image();
	cutImage.onload = function () {
		var show_width,show_height;
		if(isMobile){
			show_width = $(window).width()-50;
			show_height = $(window).height()-100;
		} else {
			if(cutImage.width>=$(window).width()-200){
				show_width = $(window).width()-50;
			} else {
				show_width = cutImage.width;
			}
			if(cutImage.height>=$(window).height()-100){
				show_height = $(window).height()-100;
			} else {
				show_height = cutImage.height;
			}
		}
		new UT.popWindow(that.src, cutImage.width, cutImage.height, {
			width: show_width,
			height: show_height
		}, "scanImg");
	};
	cutImage.src = that.src;
};
UT.getAllEmotion = function(xml) {
	try {
		var nodes = xml.getElementsByTagName("item"),
			length = nodes.length;
		var imgPath = xml.getElementsByTagName("server-path")[0].firstChild.nodeValue;
		if (!/https?:\/\//.test(imgPath)) {
            imgPath = (document.location.protocol == "https:" ?"https://":"http://") + LIM.config["chatDirDomains"] + "/" + imgPath;
        }
		var emotions = [],
			node;
		for (var i = 0; i < length; i++) {
			node = nodes[i];
			emotions.push({
				"name": node.getAttribute("name"),
				"title": node.getAttribute("title"),
				"small": imgPath + node.getElementsByTagName("small")[0].firstChild.nodeValue,
				"normal": imgPath + node.getElementsByTagName("normal")[0].firstChild.nodeValue
			});
		}
		return emotions;
	} catch (e) {
		alert(e);
	}
};
UT.getAllDefineEmotion = function(xml) {
	try {
		var themeNum = xml.getElementsByTagName("theme").length;
        var imgPath = (document.location.protocol == "https:" ?"https://":"http://") + LIM.config["appDirDomains"];
		var emotions = [],node,size;
		for (var j = 0; j < themeNum; j++){
			emotions[j] = [];
			theme = xml.getElementsByTagName("theme")[j];
			nodes = theme.getElementsByTagName("item");
			size = nodes.length;
			
			for (var i = 0; i < size; i++) {
				node = nodes[i];
				emotions[j].push({
					"name": node.getAttribute("name"),
					"title": node.getAttribute("title"),
					"src": imgPath + theme.getAttribute("folder") + node.getAttribute("pic"),
					"themeName" : theme.getAttribute("name")
				});
			}
		}
		return emotions;
	} catch (e) {
		alert(e);
	}
};
UT.od_rollOut = function(strId, strColor) {
	if (pngAlpha) {
		document.getElementById(strId).style.backgroundColor = strColor;
	} else {
		if (document.images) {
			document[strId].src = eval(strId + "off.src");
		}
	}
};
UT.od_rollOver = function(strId, strColor) {
	if (pngAlpha) {
		document.getElementById(strId).style.backgroundColor = strColor;
	} else {
		if (document.images && (flag == true)) {
			document[strId].src = eval(strId + "on.src");
		}
	}
};
UT.od_displayImage = function(strId, strPath, intWidth, intHeight, strClass, strAlt) {
	if (pngAlpha) {
		document.write('<div style="height:' + intHeight + 'px;width:' + intWidth + 'px;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + strPath + '.png\', sizingMethod=\'scale\')" id="' + strId + '" class="' + strClass + '"></div>');
	} else if (pngNormal) {
		document.write('<img src="' + strPath + '.png" width="' + intWidth + '" height="' + intHeight + '" name="' + strId + '" border="0" class="' + strClass + '" alt="' + strAlt + '" />');
	} else {
		document.write('<img src="' + strPath + '.gif" width="' + intWidth + '" height="' + intHeight + '" name="' + strId + '" border="0" class="' + strClass + '" alt="' + strAlt + '" />');
	}
};
UT.od_object_setBackground = function(){
	if (pngAlpha) {
		this.layerObject.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.path + ".png', sizingMethod='scale')";
	} else if (pngNormal) {
		this.layerObject.backgroundImage = 'url(' + this.path + '.png)';
	} else {
		this.layerObject.backgroundImage = 'url(' + this.path + '.gif)';
	}
};
UT.BrowserDetectLite = function() {
	var ua = navigator.userAgent.toLowerCase();
	this.ua = ua;
	this.isGecko = (ua.indexOf('gecko') != -1);
	this.isMozilla = (this.isGecko && ua.indexOf("gecko/") + 14 == ua.length);
	this.isNS = ((this.isGecko) ? (ua.indexOf('netscape') != -1) : ((ua.indexOf('mozilla') != -1) && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('opera') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1)));
	this.isIE = ((ua.indexOf("msie") != -1||!!window.MSStream) && (ua.indexOf("opera") == -1) && (ua.indexOf("webtv") == -1));
	this.isOpera = (ua.indexOf("opera") != -1);
	this.isKonqueror = (ua.indexOf("konqueror") != -1);
	this.isIcab = (ua.indexOf("icab") != -1);
	this.isAol = (ua.indexOf("aol") != -1);
	this.isWebtv = (ua.indexOf("webtv") != -1);
	this.isOmniweb = (ua.indexOf("omniweb") != -1);
	this.isDreamcast = (ua.indexOf("dreamcast") != -1);
	this.isIECompatible = ((ua.indexOf("msie") != -1) && !this.isIE);
	this.isNSCompatible = ((ua.indexOf("mozilla") != -1) && !this.isNS && !this.isMozilla);
	this.versionMinor = parseFloat(navigator.appVersion);
	if (this.isNS && this.isGecko) {
		this.versionMinor = parseFloat(ua.substring(ua.lastIndexOf('/') + 1));
	} else if (this.isIE && this.versionMinor >= 4) {
		this.versionMinor = parseFloat(ua.substring(ua.indexOf('msie ') + 5));
	} else if (this.isOpera) {
		if (ua.indexOf('opera/') != -1) {
			this.versionMinor = parseFloat(ua.substring(ua.indexOf('opera/') + 6));
		} else {
			this.versionMinor = parseFloat(ua.substring(ua.indexOf('opera ') + 6));
		}
	} else if (this.isKonqueror) {
		this.versionMinor = parseFloat(ua.substring(ua.indexOf('konqueror/') + 10));
	} else if (this.isIcab) {
		if (ua.indexOf('icab/') != -1) {
			this.versionMinor = parseFloat(ua.substring(ua.indexOf('icab/') + 6));
		} else {
			this.versionMinor = parseFloat(ua.substring(ua.indexOf('icab ') + 6));
		}
	} else if (this.isWebtv) {
		this.versionMinor = parseFloat(ua.substring(ua.indexOf('webtv/') + 6));
	}
	this.versionMajor = parseInt(this.versionMinor);
	this.geckoVersion = ((this.isGecko) ? ua.substring((ua.lastIndexOf('gecko/') + 6), (ua.lastIndexOf('gecko/') + 14)) : -1);
	this.isWin = (ua.indexOf('win') != -1);
	this.isWin32 = (this.isWin && (ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1));
	this.isMac = (ua.indexOf('mac') != -1);
	this.isUnix = (ua.indexOf('unix') != -1 || ua.indexOf('linux') != -1 || ua.indexOf('sunos') != -1 || ua.indexOf('bsd') != -1 || ua.indexOf('x11') != -1);
	this.isNS4x = (this.isNS && this.versionMajor == 4);
	this.isNS40x = (this.isNS4x && this.versionMinor < 4.5);
	this.isNS47x = (this.isNS4x && this.versionMinor >= 4.7);
	this.isNS4up = (this.isNS && this.versionMinor >= 4);
	this.isNS6x = (this.isNS && this.versionMajor == 6);
	this.isNS6up = (this.isNS && this.versionMajor >= 6);
	this.isIE5up = (this.isIE && this.versionMajor >= 5);
	this.isIE6x = (this.isIE && this.versionMajor == 6);
	this.isIE7x = (this.isIE && this.versionMajor == 7);
	this.isIE6up = (this.isIE && this.versionMajor > 6);
	this.isIE9down = (this.isIE && this.versionMajor < 9);
};
//获得窗口名
var documentTitle = document.title;
var changeDocumentTitleTimer = null;
UT.changeDocumentTitle = function(docTitle) {
	if (isMobile) {
		return;
	}
	try {
		var titleEl = document.getElementsByTagName("title")[0];
		var head = titleEl.parentNode;
		var hasChangedTitle = false;
		if ( !! docTitle) {
			if ( !! changeDocumentTitleTimer) {
				clearInterval(changeDocumentTitleTimer);
			}
			changeDocumentTitleTimer = setInterval(

			function () {
				if (document.all) {
					if (hasChangedTitle) {
						document.title = docTitle;
						hasChangedTitle = false;
					} else {
						document.title = "...";
						hasChangedTitle = true;
					};

				} else {
					if (hasChangedTitle) {
						head.removeChild(titleEl);
						titleEl = document.createElement("title");
						titleEl.innerHTML = docTitle;
						head.appendChild(titleEl);
						hasChangedTitle = false;
					} else {
						head.removeChild(titleEl);
						titleEl = document.createElement("title");
						titleEl.innerHTML = "...";
						head.appendChild(titleEl);
						hasChangedTitle = true;
					};
				}
			}, 500);
		} else {
			if (document.all) {
				document.title = documentTitle;
			} else {
				head.removeChild(titleEl);
				titleEl = document.createElement("title");
				titleEl.innerHTML = documentTitle;
				head.appendChild(titleEl);
			}
			clearInterval(changeDocumentTitleTimer);
		}
	} catch (e) {
		alert(e.message);
	}

};
UT.getBrowserVersion = function(){
	var browserName=navigator.userAgent.toLowerCase();
	var strBrowser = "ie";
    if(browserName.indexOf("msie 7.0")>0||browserName.indexOf("msie 8.0")>0||browserName.indexOf("msie 6.0")>0){
        strBrowser = "ie";//browserName.match(/msie ([\d.]+)/)[1];
    }else if(/firefox/i.test(browserName)){
        strBrowser = "firefox";//browserName.match(/firefox\/([\d.]+)/)[1];
    }else if(/chrome/i.test(browserName) && /webkit/i.test(browserName) && /mozilla/i.test(browserName)){
        strBrowser = "chrome";//browserName.match(/chrome\/([\d.]+)/)[1];
    }else if(/opera/i.test(browserName)){
        strBrowser = "opera";//browserName.match(/opera.([\d.]+)/)[1];
    }else if(/webkit/i.test(browserName) &&!(/chrome/i.test(browserName) && /webkit/i.test(browserName) && /mozilla/i.test(browserName))){
        strBrowser = "safari";
    }else{
        return "chrome";
    }
	return strBrowser;
};
UT.unescapeHTML = function (html) {
	var htmlNode = document.createElement("DIV");
	htmlNode.innerHTML = html;
	if (htmlNode.innerText) return htmlNode.innerText;
	return htmlNode.textContent;
};
if (!XHR) var XHR = {};
XHR.request = function (url, onload, onerror, method, params, contentType) {
	this.url = url;
	this.onload = onload;
	this.onerror = (onerror) ? onerror : this.defaultError;
	this.loadXMLDoc(url, method, params, contentType);
};
XHR.request.prototype = {
	loadXMLDoc: function (url, method, params, contentType) {
		if (!method) {
			method = "GET";
		}
		if (!contentType && method == "POST") {
			contentType = "application/x-www-form-urlencoded";
		}
		if (window.XMLHttpRequest) {
			this.req = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			this.req = new ActiveXObject("Microsoft.XMLHTTP");
		}
		if (this.req) {
			try {
				var request = this;
				this.req.onreadystatechange = function () {
					request.onReadyState.call(request);
				};
				this.req.open(method, url, true);
				if (contentType) {
					this.req.setRequestHeader("Content-Type", contentType);
				}
				this.req.send(params);
			} catch (err) {
				this.onerror.call(this);
			}
		}
	},
	onReadyState: function () {
		var req = this.req;
		var ready = req.readyState;
		if (ready == 4) {
			var httpStatus = req.status;
			if (httpStatus == 200 || httpStatus == 0) {
				this.onload.call(this);
			} else {
				this.onerror.call(this);
			}
		}
	},
	defaultError: function () {
		var info = LIM.localRes["connectError"] + "<br/>state:" + this.req.readyState + " status:" + this.req.status + " headers:" + this.req.getAllResonseHeaders;
		E.report(info, '1201');
	}
};
XHR.get = function (o) {
	if (typeof XMLHttpRequest == "undefined") {
		XMLHttpRequest = function () {
			return new ActiveXObject("Msxml2.XMLHTTP");
		};
	}
	var options = {
		type: o.type || "POST",
		url: o.url || "",
		timeout: o.timeout || 5000,
		onComplete: o.onComplete || function () {},
		onError: o.onError || function () {},
		onSuccess: o.onSuccess || function () {},
		data: o.data || null,
		contentType: o.contentType || "application/x-www-form-urlencoded",
		async: o.async || true
	};
	var xml = new XMLHttpRequest(),
		timeoutLength = options.timeout,
		requestDone = false;
	xml.open(options.type, options.url, options.async);
	if (options.type == "POST") {
		xml.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		if (xml.overrideMimeType) xml.setRequestHeader("Connection", "close");
	}
	setTimeout(function () {
		requestDone = true;
	}, timeoutLength);
	xml.onreadystatechange = function () {
		if (xml.readyState == 4 && !requestDone) {
			if (httpSuccess(xml)) {
				options.onSuccess(httpData(xml, options.type));
			} else {
				options.onError();
			}
			options.onComplete();
			xml = null;
		}
	};
	xml.send(serialize(options.data));

	function httpSuccess(r) {
		try {
			return !r.status && location.protocol == "file:" || (r.status >= 200 && r.status < 300) || r.status == 304 || navigator.userAgent.indexOf("Safari") >= 0 && typeof r.status == "undefined";
		} catch (e) {}
		return false;
	};

	function serialize(a) {
		if (!a) {
			return null;
		}
		var s = [];
		if (a.constructor == Array) {
			for (var i = 0; i < a.length; i++) {
				s.push(a[i].name + "=" + encodeURIComponent(a[i].value));
			}
		} else {
			for (var j in a) {
				s.push(j + "=" + encodeURIComponent(a[j]));
			}
		}
		return s.join("&");
	};

	function httpData(r, type) {
		var ct = r.getResponseHeader("content-type");
		var type;
		if (ct.indexOf("xml") >= 0) {
			type = "xml";
			data = r.responseXML;
		} else if (ct.indexOf("javascript") > 0) {
			type = "script";
			data = r.responseText;
		} else {
			data = r.responseText;
		}
		if ("script" == type) {
			eval.call(window, data);
		}
		return data;
	}
};
Date.prototype.format = function (format) {
	if (format == null) format = "yyyy/MM/dd HH:mm:ss.SSS";
	var year = this.getFullYear();
	var month = this.getMonth();
	var sMonth = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"][month];
	var date = this.getDate();
	var day = this.getDay();
	var hr = this.getHours();
	var min = this.getMinutes();
	var sec = this.getSeconds();
	var daysInYear = Math.ceil((this - new Date(year, 0, 0)) / 86400000);
	var weekInYear = Math.ceil((daysInYear + new Date(year, 0, 1).getDay()) / 7);
	var weekInMonth = Math.ceil((date + new Date(year, month, 1).getDay()) / 7);
	return format.replace("yyyy", year).replace("yy", year.toString().substr(2)).replace("dd", (date < 10 ? "0" : "") + date).replace("HH", (hr < 10 ? "0" : "") + hr).replace("KK", (hr % 12 < 10 ? "0" : "") + hr % 12).replace("kk", (hr > 0 && hr < 10 ? "0" : "") + (((hr + 23) % 24) + 1)).replace("hh", (hr > 0 && hr < 10 || hr > 12 && hr < 22 ? "0" : "") + (((hr + 11) % 12) + 1)).replace("mm", (min < 10 ? "0" : "") + min).replace("ss", (sec < 10 ? "0" : "") + sec).replace("SSS", this % 1000).replace("a", (hr < 12 ? "AM" : "PM")).replace("w", weekInYear).replace("W", weekInMonth).replace("E", ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"][day]).replace("D", daysInYear).replace(/MMMM+/, sMonth).replace("MMM", sMonth.substring(0, 3)).replace("MM", (month < 9 ? "0" : "") + (month + 1)).replace("F", Math.ceil(date / 7));
};
window.emReplace = function ($1) {
	var image = $1.replace(/&lt;/g, "<").replace(/&nbsp;/g, " ").replace(/%2E/g, ".").replace(/&gt;/g, "/>");
	if(image.indexOf("class=\"biaoqing\"") < 0){
		image = image.replace(/width=.*?&gt;/ig, "&gt;");
	};
	image = image.replace(/&gt;/g, "/>");
	image = image.replace(/style=".*?"/ig, "");
	//image 属性中如果有某属性值没有""或者''，那么会造成客服端不能接收到消息内容。故需要对属性值添加""  edited by xiaolong lai
	image = image.replace(/(\s+\w+)\s*=\s*([^(\/|>)("|')\s]+)/ig, '$1="$2"');
	return image;
};
window.onfocus = function(){
	try{
		UT.changeDocumentTitle();
	}catch (e) {
		// TODO: handle exception
	}
};
window.onblur = function(){
	try{
		UT.changeDocumentTitle();
	} catch (e) {
		// TODO: handle exception
	}
};